import React, { useEffect, useState } from 'react';
import { Layout, Menu, Breadcrumb } from 'antd';
import { UserOutlined, LaptopOutlined, NotificationOutlined } from '@ant-design/icons';
import { Link, Redirect, Route, Switch, useDispatch, useSelector } from 'umi'
import { Footer } from 'antd/lib/layout/layout';
import { getRoute1 } from '@/utils'

const { SubMenu } = Menu;
const { Header, Content, Sider } = Layout;

export default () => {
  const dispatch = useDispatch()
  const { currentUser } = useSelector(({ global }) => global)
  const [route1, setRoute1] = useState(getRoute1("/task"))
  console.log('route1', route1)
  useEffect(() => {
    dispatch({ type: "global/fetchCurrent" })
    // document.addEventListener("astilectron-ready", _ => {
    //   const { dialog } = window.require("electron").remote
    //   console.log("electron", dialog)
    //   console.log("window", window)
    //   window.astilectron.onMessage(msg => {
    //     console.log("on message ", msg)
    //     window.astilectron.sendMessage({ name: "set_path", payload: "are u ok?" }, msg => {
    //       console.log("send result ", msg)
    //     })
    //     dialog.showOpenDialogSync({
    //       properties: ['openFile'],
    //       title: "选择现代服目录: 魔兽安装目录\\_retail_\\Wow.exe",
    //       buttonLabel: "确定",
    //       filters: [{ name: "Wow", extensions: ["exe"] }]
    //     })
    //     return { payload: "payload" }
    //   })
    // })
  }, [])
  return (
    <Layout>
      <Header className="header">
        <div className="logo" />
        <Menu theme="dark" mode="horizontal" defaultSelectedKeys={[route1]}>
          <Menu.Item key="task">
            <Link to="/task">任务</Link>
          </Menu.Item>
          <Menu.Item key="project">
            <Link to="/project">项目</Link>
          </Menu.Item>
          <Menu.Item key="note">
            <Link to="/note">笔记</Link>
          </Menu.Item>
          <Menu.Item key="money">
            <Link to="/money">钱包</Link>
          </Menu.Item>
        </Menu>
      </Header>
      <Switch>
        <Route path="/task" component={require('./task').default} />
        <Route path="/project" component={require('./project').default} />
        <Route path="/note" component={require('./note').default} />
        <Route path="/money" component={require('./money/').default} />
        <Redirect to="/task" />
      </Switch>
    </Layout>
  );
};
